const schedule = require('node-schedule')
const Task = require('../models/task')
const Journal = require('../models/journal')

const census = (optione) => {
    schedule.scheduleJob('0 0 0 1 * *',async () => {
        // console.log('时间:' + new Date());
        let tasks = await Task.find({
            grade:0
        }).lean()

        for(let i in tasks){
            let nowtime = Date.now()
            let time = nowtime + (8 * 60 * 60 * 1000)

            let journal = new Journal()
            journal.taskId = tasks[i]._id,
            journal.taskname = tasks[i].taskname,
            journal.operate = 6,
            journal.describe = "这是统计,请勿乱动,看到及时联系管理员~~",
            journal.newData = tasks[i]
            
            journal.createdAt = new Date(time)
            journal.updatedAt = new Date(time)

            await journal.save()
            // console.log('记录成功');
        }

    });
}

module.exports = census